package com.example.pjy.service.impl;

import com.example.pjy.mapper.UserMapper;
import com.example.pjy.pojo.User1;
import com.example.pjy.service.UserService;
import com.example.pjy.utils.Md5Util;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service//交给ioc文件来管理 这样就能private UserService userService了
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;//依赖注入



    @Override
    public User1 findByUserName(String username) {
        User1 u1 = userMapper.findByUserName(username);
        return u1;
    }

    @Override
    public void register(String username, String password) {
        //加密
        String Md5String = Md5Util.getMD5String(password);//传一个明文密码会返回一个密文密码
        //添加
        userMapper.add(username,Md5String);
    }

    @Override
    public void update(User1 u1) {
        u1.setUpdateTime(LocalDateTime.now());
        userMapper.update(u1);
    }
}
